//
//  CustomNewFolderViewController.m
//  我的图书馆
//
//  Created by 孙  路 on 15-1-6.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "CustomNewFolderViewController.h"

#import "LibraryViewController.h"
@interface CustomNewFolderViewController ()

@end

@implementation CustomNewFolderViewController
- (void)dealloc
{
    [_tableArray release];
    [_tableV release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];

        self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];
        [_tableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"folderCell"];
        _tableV.delegate = self;
        _tableV.dataSource = self;
        [self.view addSubview:_tableV];

        [self createTabBar];
        [_tableV release];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
[self createNavigation];
}
#pragma mark -
#pragma mark 完成编辑文件夹(nav)
- (void)createNavigation
{
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    [aView setBackgroundColor:[UIColor orangeColor]];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setFrame:CGRectMake(315, 20, 30, 40)];
    [button addTarget:self action:@selector(backToTheList) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"完成" forState: UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [aView addSubview:button];

    [self.view addSubview:aView];
    [aView release];
}
- (void)backToTheList
{

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"listBackRightNow" object:self userInfo:nil];

}
#pragma mark -
#pragma mark 编辑文件夹选项(自定义tabBar)
- (void)createTabBar
{
    NSArray *array = [NSArray arrayWithObjects:@"建文件夹", @"重命名", @"删除", nil];
    NSArray *imageArray = [NSArray arrayWithObjects:@"iconfont-xinjianwenjianjia.png", @"iconfont-shuaxin.png", @"iconfont-shanchu.png", nil];

    UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 60)];

    [bView setBackgroundColor:[UIColor whiteColor]];
    for (int i = 0; i < 3; i++) {

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setFrame:CGRectMake(30 + 142 * i, 10, 30, 30)];
        [button addTarget:self action:@selector(editFolder:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:[imageArray objectAtIndex:i]] forState:UIControlStateNormal];
        [bView addSubview:button];

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25 + 142 * i, 40, 40, 20)];
        [label setText:[array objectAtIndex:i]];
        [label setTextAlignment:NSTextAlignmentCenter];
        [label setFont:[UIFont systemFontOfSize:10]];
        [bView addSubview:label];
        [label release];

    }
    [self.view addSubview:bView];
    [bView release];
}
- (void)editFolder:(UIButton *)sender
{

}
#pragma mark -
#pragma mark 添加文件夹

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"folderCell"];
    return cell;
}
#pragma mark -
#pragma mark cell样式编辑(处于编辑状态, 获得编辑样式, 提交样式)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath == 0) {
        return UITableViewCellEditingStyleInsert;
    }else
        return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [_tableArray removeObjectAtIndex:indexPath.row];
        [_tableV reloadData];
    }else if (editingStyle == UITableViewCellEditingStyleInsert){
        [_tableArray addObject:@"1"];
        [_tableV reloadData];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
